#! /usr/bin/python
"""
Provides methods that can be used to crack vaults secured with numbers.
"""
import sys
sys.path.insert(0, "..")
import time
from Vault import Vault

def crack(vault):
    """
    Attempts to break into a vault using numbers only
    Times the attempt and returns the guessed value and time taken
    
    Usage: (guess, data, time) = crack(number)
    """
    tick = time.time()
    
    data = None
    guess = 0
    while (data == None):
        try:
            data = vault.open(str(guess)) or vault.open(str(-guess))
        except:
            guess += 1
        
    tock = time.time()
        
    return (guess, data, (tock - tick))
        
if __name__ == "__main__":
    v = Vault("123", "This is super secret information")
    (password, data, cracktime) = crack(v)
    print "I got it! Your key was %d" % password
    print "The vault contained:"
    print "    %s" % data
    print "It took %f seconds to break" % cracktime
